// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
namespace Microsoft.Xrm.Sdk.Query
{
    using System.Runtime.Serialization;
	using Microsoft.Xrm.Sdk.Temporary;


	/// <summary>
	/// Query class similary to V4
	/// </summary>
	[KnownType(typeof(QueryExpression))]
	[KnownType(typeof(QueryByAttribute))]
	[KnownType(typeof(FetchExpression))]
	[DataContract(Name = "QueryBase", Namespace = XmlNamespaces.V5.Contracts)]
	public abstract class QueryBase : IExtensibleDataObject
	{
		[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
		internal abstract void Accept(IQueryVisitor visitor);

		#region IExtensibleDataObject Implementation
		private ExtensionDataObject ExtensionDataObject;
		public ExtensionDataObject ExtensionData
		{
			get
			{
				return ExtensionDataObject;
			}
			set
			{
				ExtensionDataObject = value;
			}
		}
		#endregion IExtensibleDataObject Implementation
	}

	[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
	internal interface IQueryVisitor
	{
		void Visit(QueryExpression query);

		void Visit(QueryByAttribute query);

		void Visit(FetchExpression query);

		void Visit(ColumnSet columnSet);

		void Visit(PagingInfo pageInfo);

		void Visit(OrderExpression order);

		void Visit(LinkEntity linkEntity);

		void Visit(FilterExpression filter);

		void Visit(ConditionExpression condition);
	}

	[DataContract(Name = "ConditionOperator", Namespace = XmlNamespaces.V5.Contracts)]
	public enum ConditionOperator
	{
		[EnumMember]
		Equal = 0,
		[EnumMember]
		NotEqual = 1,
		[EnumMember]
		GreaterThan = 2,
		[EnumMember]
		LessThan = 3,
		[EnumMember]
		GreaterEqual = 4,
		[EnumMember]
		LessEqual = 5,
		[EnumMember]
		Like = 6,
		[EnumMember]
		NotLike = 7,
		[EnumMember]
		In = 8,
		[EnumMember]
		NotIn = 9,
		[EnumMember]
		Between = 10,
		[EnumMember]
		NotBetween = 11,
		[EnumMember]
		Null = 12,
		[EnumMember]
		NotNull = 13,
		// date time operators. In the parity of unmanged platform query plan.
		[EnumMember]
		Yesterday = 14,
		[EnumMember]
		Today = 15,
		[EnumMember]
		Tomorrow = 16,
		[EnumMember]
		Last7Days = 17,
		[EnumMember]
		Next7Days = 18,
		[EnumMember]
		LastWeek = 19,
		[EnumMember]
		ThisWeek = 20,
		[EnumMember]
		NextWeek = 21,
		[EnumMember]
		LastMonth = 22,
		[EnumMember]
		ThisMonth = 23,
		[EnumMember]
		NextMonth = 24,
		[EnumMember]
		On = 25,
		[EnumMember]
		OnOrBefore = 26,
		[EnumMember]
		OnOrAfter = 27,
		[EnumMember]
		LastYear = 28,
		[EnumMember]
		ThisYear = 29,
		[EnumMember]
		NextYear = 30,
		[EnumMember]
		LastXHours = 31,
		[EnumMember]
		NextXHours = 32,
		[EnumMember]
		LastXDays = 33,
		[EnumMember]
		NextXDays = 34,
		[EnumMember]
		LastXWeeks = 35,
		[EnumMember]
		NextXWeeks = 36,
		[EnumMember]
		LastXMonths = 37,
		[EnumMember]
		NextXMonths = 38,
		[EnumMember]
		LastXYears = 39,
		[EnumMember]
		NextXYears = 40,
		[EnumMember]
		EqualUserId = 41,
		[EnumMember]
		NotEqualUserId = 42,
		[EnumMember]
		EqualBusinessId = 43,
		[EnumMember]
		NotEqualBusinessId = 44,
		[EnumMember]
		ChildOf = 45,           // Used for offline filter queries
		[EnumMember]
		Mask = 46,			    // Tests condition "value & mask == value", i.e. "all flags are set"
		[EnumMember]
		NotMask = 47,			// Tests condition "value & mask == 0", i.e. "no flags are set"
		[EnumMember]
		MasksSelect = 48,		// Tests condition "value & mask <> 0", i.e. "some flags are set"
		[EnumMember]
		Contains = 49,
		[EnumMember]
		DoesNotContain = 50,
		[EnumMember]
		EqualUserLanguage = 51,
		[EnumMember]
		NotOn = 52,
		[EnumMember]
		OlderThanXMonths = 53,
		[EnumMember]
		BeginsWith = 54,
		[EnumMember]
		DoesNotBeginWith = 55,
		[EnumMember]
		EndsWith = 56,
		[EnumMember]
		DoesNotEndWith = 57,
		[EnumMember]
		ThisFiscalYear = 58,
		[EnumMember]
		ThisFiscalPeriod = 59,
		[EnumMember]
		NextFiscalYear = 60,
		[EnumMember]
		NextFiscalPeriod = 61,
		[EnumMember]
		LastFiscalYear = 62,
		[EnumMember]
		LastFiscalPeriod = 63,
		[EnumMember]
		LastXFiscalYears = 64,
		[EnumMember]
		LastXFiscalPeriods = 65,
		[EnumMember]
		NextXFiscalYears = 66,
		[EnumMember]
		NextXFiscalPeriods = 67,
		[EnumMember]
		InFiscalYear = 68,
		[EnumMember]
		InFiscalPeriod = 69,
		[EnumMember]
		InFiscalPeriodAndYear = 70,
		[EnumMember]
		InOrBeforeFiscalPeriodAndYear = 71,
		[EnumMember]
		InOrAfterFiscalPeriodAndYear = 72,
		[EnumMember]
		EqualUserTeams = 73
	}

	[DataContract(Name = "LogicalOperator", Namespace = XmlNamespaces.V5.Contracts)]
	public enum LogicalOperator
	{
		[EnumMember]
		And,
		[EnumMember]
		Or,
	}

	[DataContract(Name = "JoinOperator", Namespace = XmlNamespaces.V5.Contracts)]
	public enum JoinOperator
	{
		[EnumMember]
		Inner = 0,
		[EnumMember]
		LeftOuter = 1,
		[EnumMember]
		Natural
	}

	[DataContract(Name = "OrderType", Namespace = XmlNamespaces.V5.Contracts)]
	public enum OrderType
	{
		[EnumMember]
		Ascending,
		[EnumMember]
		Descending
	}
}

